﻿#region
/*******************************************************************************
** File Name:		    AdminUserService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;
using Spring.Transaction.Interceptor;
using JCode.Common;
using AutoMapper;

namespace EWineShop.Service
{
    public class AdminUserService : IAdminUserService
    {
        public IAdminUser adminUser { get; set; }
        
        public void AddAdminUser(AdminUserModel model)
        {
            EAdminUser entity = ToEntity(model);

            adminUser.AddAdminUser(entity);
        }

        public void UpdateByUserID(AdminUserModel model)
        {
            EAdminUser entity = ToEntity(model);
        
            adminUser.UpdateByUserID(entity);
          
            
        }

        [LoggingAttributes]
        [Transaction]
        public void DeleteByUserID(System.Int64 userID)
        {
            
            
            adminUser.DeleteByUserID(userID);

        }

        public AdminUserModel GetByUserID(System.Int64 userID)
        {


            EAdminUser entity = adminUser.GetByUserID(userID);


            AdminUserModel model = entity.ToMap<EAdminUser, AdminUserModel>();

            
            return model;
        }


        #region  Auto Generation
        public IList<AdminUserModel> GetAll()
        {
            IList<EAdminUser> entity = adminUser.GetAll();

            var list = entity.ToMap<IList<EAdminUser>, IList<AdminUserModel>>();

            return list;

        }

        private AdminUserModel ToModel(EAdminUser entity)
        {
            Mapper.CreateMap<EAdminUser, AdminUserModel>();

            
            return Mapper.Map<EAdminUser, AdminUserModel>(entity);
        }

        private EAdminUser ToEntity(AdminUserModel model)
        {
            return Mapper.Map<AdminUserModel, EAdminUser>(model);
        }



        #endregion


        public AdminUserModel GetByUserName(string userName)
        {
            EAdminUser entity = adminUser.GetByUserName(userName);

            AdminUserModel model = ToModel(entity);

            return model;
        }
    }
}